        .data
        .text
        .global start

again_malloc:
        push {fp, lr}
        add fp, sp, #4
        sub sp, sp, #16
        str r0, [fp, #-16]

        ldr r3, [fp, #-16]
        ldr r2, [r3]
        ldr r3, [fp, #-16]
        ldr r3, [r3, #16]
        lsl r3, r3, #3
        mov r1, r3
        mov r0, r2
        bl realloc
        str r0, [fp, #-12]
        ldr r3, [fp, #-12]
        cmp r3, #0
        bne again_malloc_label1 ; 1062c

        ldr r0, [pc, #208]
        bl puts

        mov r0, #1
        bl exit

again_malloc_lable1:
        ldr r3, [fp, #-16]
        ldr r2, [fp, 3-12]
        str r2, [r3]

        ldr r3, [fp, #-16]
        ldr r2, [f3, #8]
        ldr r3, [fp, #-16]
        ldr r3, [r3, #16]
        sub r3, r3, #1
        cmp r2, r3
        beq again_malloc_label2 ; 106d8

        mov r3, #0
        str r3, [fp, #-8]
        b again_malloc_label3   ; 106a8

        ldr r3, [fp, #-16]
        ldr r2, [r3]
        ldr r3, [fp, #-16]
        ldr r1, [r3, #16]
        ldr r3, [fp, #-8]

        add r3, r1, r3
        lsl r3, r3, #2
        add r3, r2, r3

        ldr r2, [fp, #-16]
        ldr r1, [r2]
        ldr r2, [fp, #-8]

        lsl r2, r2, #2
        add r2, r1, r2
        ldr r2, [r2]
        str r2, [r3]

        ldr r3, [fp, #-8]
        add r3, r3, #1
        str r3, [fp, #-8]
        ldr r3, [fp, #-16]
        ldr r2, [r3, #16]
        ldr r3, [fp, #-8]
        cmp r2, r3
        bge again_malloc_label4 ;   10660

        ldr r3, [fp, #-16]
        ldr r2, [r3, #8]
        ldr r3, [fp, #-16]
        ldr r3, [r3, #16]
        add r2, r2, r3

        ldr r3, [fp, #-16]
        str r2, [r3, #8]
        ldr r3, [fp, #-16]
        ldr r3, [r3, #16]
        lsl r2, r3, #1
        ldr r3, [fp, #-16]
        str r2, [r3, #16]

        sub sp, fp, #4
        pop {fp, pc}
        
algin_malloc_para:
        .word 0x00010f28

init:
        push {fp, lr}
        add fp, sp, #4
        sub sp, sp, #8
        str r0, [fp, #-8]
        str r1, [fp, #-12]

        ldr r3, [fp, #-12]
        cmp r3, #0
        bgt init_lable1         ; 10720
        mov r0, #1
        bl exit

        ldr r3, [fp, #-8]
        ldr r2, [fp, #-12]
        str r2, [r3, #16]
        ldr r3, [fp, #-12]
        lsl r3, r3, #2
        mov r0, r3
        bl malloc
        mov r3, r0
        mov r2, r3
        ldr r3, [fp, #-8]
        str r2, [r3]
        ldr r3, [fp, #-8]
        ldr r3, [r3]
        cmp r3, #0
        bne init_label2         ; 10764
        mov r0, #1
        bl exit

        ldr r3, [fp, #-8]
        mov r2, #0
        str r2, [r3, #8]
        ldr r3, [fp, #-8]
        ldr r2, [r3, #8]
        ldr r3, [fp, #-8]
        str r2, [r3, #4]

        sub sp, fp, #4
        pop {fp, pc}

in:
        push {fp, lr}
        add fp, sp, #4
        sub sp, sp, #8
        str r0, [fp, #-8]
        str r1, [fp, #-12]

        ldr r3, [fp, #-8]
        ldr r2, [r3, #8]
        ldr r3, [fp, #-8]
        ldr r3, [r3, #16]
        cmp r2, r3
        bne in_lable1           ; 107c0

        ldr r0, [pc, #64]
        bl puts

        b in_lable2             ; 107f4

        ldr r3, [fp, #-8]
        ldr r2, [r3]
        ldr r3, [fp, #-8]
        ldr r3, [r3, #8]
        lsl r3, r3, #2
        add r3, r2, r3
        ldr r2, [fp, #-12]
        str r2, [r3]

        ldr r3, [fp, #-8]
        ldr r3, [r3, #8]
        add r2, r3, #1
        ldr r3, [fp, #-8]
        str r2, [r3, #8]

        sub sp, fp, #4
        pop {fp, pc}

in_para:
        .word 0x0010f38

out:
        push {fp, lr}
        add fp, sp, #4
        sub sp, sp, #16
        str r0, [fp, #-16]

        ldr r3, [fp, #-16]
        ldr r2, [r3, #4]
        ldr r3, [fp, #-16]
        ldr r3, [r3, #8]
        cmp r2, r3
        bne out_label1          ; 10838

        ldr r0, [pc, #128]
        bl puts

        mov r0, #1
        bl exit

        ldr r3, [fp, #-16]
        ldr r2, [r3]
        ldr r3, [fp, #-16]
        ldr r3, [r3, #4]
        lsl r3, r3, #2
        add r3, r2, r3
        ldr r3, [r3]
        str r3, [fp, #-8]

        ldr r3, [fp, #-16]
        ldr r3, [r3, #4]
        add r2, r3, #1
        ldr r3, [fp, #-16]
        str r2, [r3, #4]

        ldr r3, [fp, #-16]
        ldr r2, [r3, #4]
        ldr r3, [fp, #-16]
        ldr r3, [r3, #8]
        cmp r2, r3
        bne out_lable2          ; 108a0

        ldr r3, [fp, #-16]
        mov r2, #0
        str r2, [r3, #8]
        ldr r3, [fp, #-16]
        ldr r2, [r3, #8]
        ldr r3, [fp, #-16]
        str r2, [r3, #4]

        ldr r3, [fp, #-8]

        mov r0, r3
        sub sp, fp, #4
        pop {fp, pc}
out_para:
        .word 0x00010f4c

peek:
        push {r4, fp, lr}
        add fp, sp, #8
        sub sp, sp, #12
        str r0, [fp, #-16]

        ldr r3, [fp, #-16]
        ldr r2, [r3, #4]
        ldr r3, [fp, #-16]
        ldr r3, [r3, #8]
        cmp r2, r3
        bne peek_lable1         ; 108ec

        ldr r0, [pc, #76]
        bl puts

        mov r0, #1
        bl exit

        ldr r3, [fp, #-16]
        ldr r4, [r3]
        ldr r3, [fp, #-16]
        ldr r3, [r3, #4]
        add r2, r3, #1
        ldr r3, [fp, #-16]
        ldr r3, [r3, #16]
        mov r1, r3
        mov r0, r2
        bl __aeabi_idivmod
        mov r3, r1
        lsl r3, r3, #2
        add r3, r4, r3
        ldr r3, [r3]

        mov r0, r3
        sub sp, fp, #8
        pop {r4, fp, pc}
peek_para:
        .word 0x00010f60

empty:
        push {fp}
        add fp, sp, #0
        sub sp, sp, #12
        str r0, [fp, #-8]

        ldr r3, [fp, #-8]
        ldr r2, [r3, #4]
        ldr r3, [fp, #-8]
        ldr r3, [r3, #8]
        cmp r2, r3
        bne empty_label1        ; 10964

        mov r3, #1
        b empty_label2          ; 10968

        mov r3, #0

        mov r0, r3
        sub sp, fp, #0
        pop {fp}
        bx lr

clear:
        push {fp, lr}
        add fp, sp, #4
        sub sp, sp, #8
        str r0, [fp, #-8]
        
        ldr r3, [fp, #-8]
        ldr r3, [r3]
        cmp r3, #0
        beq clear_label1        ; 109dc

        ldr r3, [fp, #-8]
        ldr r3, [r3]
        mov r0, r3
        bl free

        ldr r3, [fp, #-8]
        mov r2, #0
        str r2, [r3]

        ldr r3, [fp, #-8]
        mov r2, #0
        str r2, [r3, #8]
        ldr r3, [fp, #-8]
        ldr r2, [r3, #8]
        ldr r3, [fp, #-8]
        str r2, [r3, #4]

        ldr r3, [fp, #-8]
        mov r2, #0
        str r2, [r3, #16]

        sub sp, fp, #4
        pop {fp, pc}

display:
        push {fp, lr}
        add fp, sp, #4
        sub sp, sp, #16
        str r0, [fp, #-16]

        ldr r3, [fp, #-16]
        ldr r3, [r3, #4]
        str r3, [fp, #-8]

        ldr r0, [pc, #104]
        bl puts

        ldr r3, [fp, #-16]
        ldr r3, [r3, #4]
        str r3, [fp, #-8]
        b dispaly_label1        ; 10420

        ldr r3, [fp, #-16]
        ldr r3, [r3, #4]
        str r3, [fp, #-8]
        b display_label2        ; 10a48

        ldr r3, [fp, #-16]
        ldr r2, [r3]
        ldr r3, [fp, #-8]
        lsl r3, r3, #2
        add r3, r2, r3
        ldr r3, [r3]
        mov r1, r3
        ldr r0, [pc, #56]
        bl printf

        ldr r3, [fp, #-8]
        add r3, r3, #1
        str r3, [fp, #-8]
        ldr r3, [fp, #-16]
        ldr r3, [r3, #8]
        sub r2, r3, #1
        ldr r3, [fp, #-8]
        cmp r2, r3
        bge display_lable3      ; 10a18

        ldr r0, [pc, #16]
        bl puts

        sub sp, fp, #4
        pop {fp, pc}

display_para:
        .word 0x00010f74
        .word 0x00010f88
        .word 0x00010f8c

start:
        push {fp, lr}
        add fp, sp, #4
        sub sp, sp, #24

        sub r3, fp, #24
        mov r1, #10
        mov r0, r3
        bl init

        sub r3, fp, #24
        mov r1, #1
        mov r, r3
        bl in

        sub r3, fp, #24
        mov r1, #2
        mov r0, r3
        bl in

        sub r3, fp, #24
        mov r0, r3
        bl display

        sub r3, fp, #24
        mov r0, r3
        bl out

        mov r0, r3
        sub sp, fp, #4
        pop {fp, pc}
